package com.ruoyi.business.controller;


import com.ruoyi.business.dto.WxLoginDto;
import com.ruoyi.business.service.IMobileWechatService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author liumaotong
 * @Description 微信相关操作的接口
 * 也包含小程序用相关共通
 * @Date 2024/1/6
 */
@RestController
@RequestMapping("/mobile/wechat")
public class MobileWechatController extends BaseController {


    @Autowired
    private IMobileWechatService mobileWechatService;
    @Autowired
    private ISysDictTypeService dictTypeService;


    /**
     * @Author liumaotong
     * @Description 小程序登录
     * @Date 2024/1/7
     * @Param [loginDto]
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @RequestMapping("/wxLogin")
    public AjaxResult wxLogin(@RequestBody WxLoginDto loginDto) throws Exception {
        return AjaxResult.success(mobileWechatService.wxLogin(loginDto));
    }

    /**
     * @Author liumaotong
     * @Description 获取用户手机号
     * @Date 2024/1/18
     * @Param [wechatInfo]
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @RequestMapping("/getPhoneNumber")
    public AjaxResult wxGetPhoneNumber(@RequestBody WxLoginDto loginDto) throws Exception {
        return AjaxResult.success(mobileWechatService.getPhoneNumber(loginDto));
    }

    /**
     * @Author liumaotong
     * @Description 根据字典type 查询字典值
     * @Date 2024/1/12
     * @Param [dictType]
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping(value = "/type/{dictType}")
    public AjaxResult dictType(@PathVariable("dictType") String dictType)
    {
        List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
        if (StringUtils.isNull(data))
        {
            data = new ArrayList<SysDictData>();
        }
        return success(data);
    }

}
